package util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;
import java.util.StringTokenizer;

public class Constants 
{
	public static Constants instance = new Constants();
	public List<List<Object>> objects;
	public Hashtable<String, Object> constants;
	
	private Constants()
	{
		establishInput();
		establishConstants();
	}

	private void establishInput() {
		objects = new ArrayList<List<Object>>();
		
		try 
		{
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("inputs.txt"))));
		
			String line;
			
			while((line = reader.readLine()) != null)
			{
				if(!line.contains("#") && !line.trim().equals(""))
				{
					List<Object> list = new ArrayList<Object>();
					
					StringTokenizer token = new StringTokenizer(line," ");
					
					while(token.hasMoreTokens())
					{
						list.add(token.nextToken());
					}
					
					objects.add(list);
				}
			}
			
			reader.close();
		} 
		catch(Exception e) 
		{
			e.printStackTrace();
		}
		
	}

	private void establishConstants() {
		constants = new Hashtable<String, Object>();
		
		try 
		{
			BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File("constants.txt"))));
		
			String line;
			
			while((line = reader.readLine()) != null)
			{
				if(!line.contains("#") && !line.trim().equals(""))
				{
					StringTokenizer token = new StringTokenizer(line," ");
					
					constants.put(token.nextToken(), token.nextToken());
				}
			}
			
			reader.close();
		} 
		catch(Exception e) 
		{
			e.printStackTrace();
		}
		
	}
	
	public void resetInput()
	{
		establishInput();
	}
}
